﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;

namespace Ev.CaiPiao
{
    public static class StaticEmail
    {
        //腾讯企业邮箱
        //static string emailAcount = "chinaa@zhimabaobao.com";
        //static string emailPassword = "Qwerty123";

        //163网易
        //static string emailAcount = "chinaatoken@163.com";
        //static string emailPassword = "xr9332958";//授权码
        //static string emailAcount = "boaosady@163.com";
        //static string emailPassword = "Evan123";//授权码
        static string emailAcount = "boaosady@163.com";
        static string emailPassword = "Evan123";//授权码

        static string emailTitle = "ChinaA验证码";

        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="email"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static bool sendCode(string email,string title,string strContent)
        {

            emailTitle = title;
            var result = SendMails(email, strContent);
            return result ;
        }


        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private static bool SendMails(string email, string content)
        {
            try
            {
                MailAddress receiver = new MailAddress(email, "");
                MailAddress sender = new MailAddress(emailAcount, "彩票API机器人");
                MailMessage message = new MailMessage();
                message.From = sender;//发件人
                message.To.Add(new MailAddress(email,"彩票API客户"));//收件人
                message.CC.Add(sender);//抄送人
                message.Subject = emailTitle;//标题
                message.Body = content;//内容
                message.IsBodyHtml = true;//是否支持内容为HTML

                SmtpClient client = new SmtpClient();
                client.Host = "smtp.163.com";
                //client.Port = 465; 
                client.EnableSsl = true;//是否启用SSL
                client.Timeout = 10000;//超时
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential(emailAcount, emailPassword);
                client.Send(message); 
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}